<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * @name Data
 * @file data.php
 * @author Daniel Valkovič
 * @version 1.0
 * @package CodeIgniter
 * @subpackage Controllers
 * @section POPIS
 * Tento kontroler slúži na import a export obsahu tabuliek databázy. Tieto kontrolery 
 * sú defaultne prístupné iba pre admina.
 */
class Data extends MY_Controller {

    function __construct() {
        parent::__construct();
        //$this->load->model(array('worktypemodel', 'languagemodel', 'programosmodel', 'studylevelmodel', 'classroomsubjectmodel', 'adminsmodel'));  // používanie Modelov z Acicrud
    }

    /**
     * Funkcia zobrazí základnú stránku práce s databázou.
     */
    public function index() {
        $data['title'] = 'Databázy';
        if (!$this->user->isLogged()) {
            $data['error_message'] = 'Nie ste prihlásený!';
            $data['redirect_to'] = ''; // url , kde sa bude redirectovat '' home, inac napr 'programs_managment/index' inde
            $this->load->view('templates/headers/h_redirect_index', $data, FALSE);
            $this->load->view('auth/log_message', $data, FALSE);
            $this->load->view('templates/footers/footer', null, FALSE);
            return;
        }
        $this->load->view('templates/headers/header', $data, FALSE);
        $this->load->view('data/index', null, FALSE);
        $this->load->view('templates/footers/footer', null, FALSE);
    }

    public function export($table) {
        $data['table'] = $table;
        $model = str_replace('_', '', $table)."model";
        $data['head'] = "";
        $this->load->model($model);
        $data['database'] = $this->$model->getAll();
        foreach ($this->$model->fields as $key => $value) {
            $data['head'] .= $key . "\t";
        }
        $data['head'] .= "\n";
        $this->load->view('data/export', $data, FALSE);
    }

}

/* End of file structure_managment.php */
/* Location: ./application/controllers/structure_managment.php */
